package org.shoukaiseki.web.config;

import org.apache.commons.io.IOUtils;
import org.shoukaiseki.web.config.exec.SeleniumActuator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;

/**
 **/
@Component
public class SeleniumComponent {

    @Value("${webdriver.firefox.bin}")
    String firefox;

    @Value("${webdriver.gecko.driver}")
    String geckodriver;


    @PostConstruct
    public void init() throws IOException {
        System.setProperty ( "webdriver.firefox.bin" , firefox );
        System.setProperty ( "webdriver.gecko.driver" , geckodriver );
        ClassLoader classLoader = SeleniumComponent.class.getClassLoader();
        InputStream stencilsetStream = classLoader.getResourceAsStream("search.js");
        String searchJs = IOUtils.toString(stencilsetStream, "utf-8");
        SeleniumActuator.setSearchJs(searchJs);
    }

}
